#include "Shm.hpp"
#include "namedPipe.hpp"

//read
int main()
{
    // 1. 创建共享内存
    Shm shm(gpathname, gproj_id, gCreater);
    char* shmaddr = (char*)shm.Addr();

    shm.DebugShm();

    // 2. 创建管道
    NamedPiped fifo(comm_path, Creater);
    fifo.OpenForRead();

    while(true)
    {
        std::string temp;
        int n = fifo.ReadNamedPipe(&temp);

        std::cout << "shm:> " <<shmaddr<<std::endl;
        // sleep(1);

        if (n > 0)
        {
            continue;
        }
        else if (n == 0)
        {
            std::cout << "Client quit, Server Too!" << std::endl;
            break;
        }
        else
        {
            std::cout << "fifo.ReadNamedPipe Error" << std::endl;
            break;
        }
    }

    sleep(3);

    return 0;
}